package JUnit3;
import junit.framework.TestCase;

public class LiczbaTest extends TestCase {
	
	private Liczba testedObject = null;

	public void setUp() throws NumberOutOfBoundsException {
		this.testedObject = new Liczba(0);
	}
	
	public void testCheckReferenceIsNotNULL() {
		assertNotNull(this.testedObject);
	}
	
	public void testCheckSetter() {
		try {
			this.testedObject.setLiczba(-1);
			fail();
		} catch (NumberOutOfBoundsException ex) {
			
		}
		
		try {
			this.testedObject.setLiczba(0);
		} catch (NumberOutOfBoundsException ex) {
			fail("catched wrong exception");
		}
		
		try {
			this.testedObject.setLiczba(1);
		} catch (NumberOutOfBoundsException ex) {
			fail("wrong exception catched");
		}
	}
	
	public void testCheckBase() throws NumberOutOfBoundsException {
		this.testedObject.setLiczba(1);
		
		try {
			this.testedObject.getNumberInBase(1);
			fail();
		} catch (WrongBaseException ex) {
			
		}
		try {
			this.testedObject.getNumberInBase(2);
		} catch (WrongBaseException ex) {
			fail("catched wrong exception");
		}
		try {
			this.testedObject.getNumberInBase(16);
		} catch (WrongBaseException ex) {
			fail ("catched wrong exception");
		}
		try {
			this.testedObject.getNumberInBase(17);
			fail();
		} catch (WrongBaseException ex) {
			
		}
	}
	
	public void testCheck0() throws NumberOutOfBoundsException, WrongBaseException {
		this.testedObject.setLiczba(0);
		
		assertEquals("0", this.testedObject.getNumberInBase(2));
		assertEquals("0", this.testedObject.getNumberInBase(3));
		assertEquals("0", this.testedObject.getNumberInBase(4));
		assertEquals("0", this.testedObject.getNumberInBase(5));
		assertEquals("0", this.testedObject.getNumberInBase(6));
		assertEquals("0", this.testedObject.getNumberInBase(7));
		assertEquals("0", this.testedObject.getNumberInBase(8));
		assertEquals("0", this.testedObject.getNumberInBase(9));
		assertEquals("0", this.testedObject.getNumberInBase(10));
		assertEquals("0", this.testedObject.getNumberInBase(11));
		assertEquals("0", this.testedObject.getNumberInBase(12));
		assertEquals("0", this.testedObject.getNumberInBase(13));
		assertEquals("0", this.testedObject.getNumberInBase(14));
		assertEquals("0", this.testedObject.getNumberInBase(15));
		assertEquals("0", this.testedObject.getNumberInBase(16));

	}
	
	public void testCheck1() throws NumberOutOfBoundsException, WrongBaseException {
		this.testedObject.setLiczba(1);
		
		assertEquals("1", this.testedObject.getNumberInBase(2));
		assertEquals("1", this.testedObject.getNumberInBase(3));
		assertEquals("1", this.testedObject.getNumberInBase(4));
		assertEquals("1", this.testedObject.getNumberInBase(5));
		assertEquals("1", this.testedObject.getNumberInBase(6));
		assertEquals("1", this.testedObject.getNumberInBase(7));
		assertEquals("1", this.testedObject.getNumberInBase(8));
		assertEquals("1", this.testedObject.getNumberInBase(9));
		assertEquals("1", this.testedObject.getNumberInBase(10));
		assertEquals("1", this.testedObject.getNumberInBase(11));
		assertEquals("1", this.testedObject.getNumberInBase(12));
		assertEquals("1", this.testedObject.getNumberInBase(13));
		assertEquals("1", this.testedObject.getNumberInBase(14));
		assertEquals("1", this.testedObject.getNumberInBase(15));
		assertEquals("testCheck1 failed on base 16","1", this.testedObject.getNumberInBase(16));
	}
	public void testAgnieszki() throws NumberOutOfBoundsException, WrongBaseException{
		this.testedObject.setLiczba(21);
		assertEquals( this.testedObject.getNumberInBase(16),"15");
	}
	
	
	public void test6() throws NumberOutOfBoundsException, WrongBaseException
	{
		this.testedObject.setLiczba(6);
		assertEquals( this.testedObject.getNumberInBase(3), "20");
	}
	
	public void test20() throws NumberOutOfBoundsException, WrongBaseException
	{
		this.testedObject.setLiczba(20);
		assertEquals( this.testedObject.getNumberInBase(11), "19");
	}
	

	public void tearDown() {
		this.testedObject = null;
	}

}